package GUI.Administracion;

import java.awt.BorderLayout;
import java.awt.EventQueue;

import javax.swing.JFrame;
import javax.swing.JPanel;
import javax.swing.border.EmptyBorder;
import javax.swing.GroupLayout;
import javax.swing.GroupLayout.Alignment;
import javax.swing.ImageIcon;
import javax.swing.JLabel;
import javax.swing.JComboBox;
import javax.swing.JTextField;
import javax.swing.JScrollPane;
import javax.swing.LayoutStyle.ComponentPlacement;
import javax.swing.JTable;
import javax.swing.table.DefaultTableModel;
import javax.swing.JButton;

import BBDD.ManageAlumno;
import BBDD.ManageModulo;

import java.awt.event.ActionListener;
import java.awt.event.ActionEvent;

public class NuevoModulo extends JFrame {

	private JPanel contentPane;
	private JTextField txtIdModulo;
	private JTextField txtHoras;
	private JTextField txtCurso;
	private JTable table;
	private ManageModulo controladorBD;
	private JTextField txtIdCiclo;
	private JTextField txtNombreCiclo;

	/**
	 * Launch the application.
	 */
	public static void main(String[] args) {
		EventQueue.invokeLater(new Runnable() {
			public void run() {
				try {
					NuevoModulo frame = new NuevoModulo();
					frame.setVisible(true);
				} catch (Exception e) {
					e.printStackTrace();
				}
			}
		});
	}

	/**
	 * Create the frame.
	 */
	public NuevoModulo() {
		setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
		setBounds(100, 100, 468, 300);
		contentPane = new JPanel();
		contentPane.setBorder(new EmptyBorder(5, 5, 5, 5));
		setContentPane(contentPane);
		
		JPanel panel = new JPanel();
		panel.setLayout(null);
		
		JLabel label = new JLabel("Id M\u00F3dulo");
		label.setBounds(0, 3, 59, 14);
		panel.add(label);
		
		JLabel label_1 = new JLabel("Id Ciclo");
		label_1.setBounds(0, 34, 51, 14);
		panel.add(label_1);
		
		txtIdModulo = new JTextField();
		txtIdModulo.setColumns(10);
		txtIdModulo.setBounds(55, 0, 86, 20);
		panel.add(txtIdModulo);
		
		JLabel label_2 = new JLabel("Horas");
		label_2.setBounds(151, 3, 51, 14);
		panel.add(label_2);
		
		txtHoras = new JTextField();
		txtHoras.setColumns(10);
		txtHoras.setBounds(230, 0, 86, 20);
		panel.add(txtHoras);
		
		JLabel lbl = new JLabel("Curso");
		lbl.setBounds(326, 3, 47, 14);
		panel.add(lbl);
		
		txtCurso = new JTextField();
		txtCurso.setColumns(10);
		txtCurso.setBounds(365, 0, 54, 20);
		panel.add(txtCurso);
		
		JScrollPane scrollPane = new JScrollPane();
		
		JButton btnVolver = new JButton("Volver");
		btnVolver.setIcon(new ImageIcon(NuevoProfesor.class.getResource("/Utilidades/volver.png")));
		btnVolver.addActionListener(new ActionListener() {
			public void actionPerformed(ActionEvent e) {
				dispose();
			}
		});
		GroupLayout gl_contentPane = new GroupLayout(contentPane);
		gl_contentPane.setHorizontalGroup(
			gl_contentPane.createParallelGroup(Alignment.TRAILING)
				.addGroup(gl_contentPane.createSequentialGroup()
					.addGroup(gl_contentPane.createParallelGroup(Alignment.LEADING)
						.addGroup(gl_contentPane.createSequentialGroup()
							.addContainerGap()
							.addComponent(panel, GroupLayout.PREFERRED_SIZE, 429, GroupLayout.PREFERRED_SIZE))
						.addGroup(gl_contentPane.createSequentialGroup()
							.addContainerGap()
							.addComponent(scrollPane, GroupLayout.DEFAULT_SIZE, 429, Short.MAX_VALUE))
						.addGroup(Alignment.TRAILING, gl_contentPane.createSequentialGroup()
							.addContainerGap(333, Short.MAX_VALUE)
							.addComponent(btnVolver)))
					.addContainerGap())
		);
		gl_contentPane.setVerticalGroup(
			gl_contentPane.createParallelGroup(Alignment.LEADING)
				.addGroup(gl_contentPane.createSequentialGroup()
					.addContainerGap()
					.addComponent(panel, GroupLayout.PREFERRED_SIZE, 65, GroupLayout.PREFERRED_SIZE)
					.addPreferredGap(ComponentPlacement.RELATED)
					.addComponent(scrollPane, GroupLayout.PREFERRED_SIZE, 111, GroupLayout.PREFERRED_SIZE)
					.addPreferredGap(ComponentPlacement.UNRELATED)
					.addComponent(btnVolver)
					.addContainerGap(GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE))
		);
		
		JButton btnGuardar = new JButton("Guardar");
		btnGuardar.addActionListener(new ActionListener() {
			public void actionPerformed(ActionEvent e) {
				controladorBD = new ManageModulo();

				String query="INSERT INTO modulo VALUES (" + txtIdModulo.getText() + ", '"
								+ txtIdCiclo.getText() + "', '"
								+ txtNombreCiclo.getText() + "', '"
								+ txtHoras.getText() + "', '" + txtCurso.getText()+"')";
				
				
				controladorBD.updateModulo(query);
			}
			
		});
		btnGuardar.setBounds(330, 30, 89, 23);
		panel.add(btnGuardar);
		
		txtIdCiclo = new JTextField();
		txtIdCiclo.setBounds(55, 31, 86, 20);
		panel.add(txtIdCiclo);
		txtIdCiclo.setColumns(10);
		
		txtNombreCiclo = new JTextField();
		txtNombreCiclo.setColumns(10);
		txtNombreCiclo.setBounds(230, 31, 86, 20);
		panel.add(txtNombreCiclo);
		
		JLabel label_4 = new JLabel("Nombre Ciclo");
		label_4.setBounds(151, 34, 75, 14);
		panel.add(label_4);
		
		table = new JTable();
		table.setModel(new DefaultTableModel(
			new Object[][] {
				{null, null, null, null, null},
				{null, null, null, null, null},
				{null, null, null, null, null},
			},
			new String[] {
				"Id M\u00F3dulo", "Id Ciclo", "Nombre Ciclo", "Horas M\u00F3dulo", "Curso"
			}
		));
		scrollPane.setViewportView(table);
		contentPane.setLayout(gl_contentPane);
	}
}
